package cz.possoft.explorer.meta;

import java.lang.reflect.Method;
import java.util.Collection;

/**
 * metainformation about single method.
 * 
 * @author <a href="mailto:mposolda@gmail.com">Marek Posolda</a>
 * @version $Revision$
 */
public class MethodMetadata
{
   private final String methodName;
   
   private final Method method;
   
   private final Collection<ParamMetadata> paramMetadata;
      
   private final boolean isCallable;
   
   public MethodMetadata(String methodName, Method method, Collection<ParamMetadata> paramMetadata)
   {
      this.methodName = methodName;
      this.method = method;
      this.paramMetadata = paramMetadata;
      
      // Method is callable for us if all paramMetadata types are convertable
      boolean callable = true;
      for (ParamMetadata param : paramMetadata)
      {
         if (!param.isConvertable())
         {
            callable = false;
            break;
         }
      }
      isCallable = callable;
   }
   
   public String getMethodName()
   {
      return methodName;
   }

   public Method getMethod()
   {
      return method;
   }

   public Collection<ParamMetadata> getParamMetadata()
   {
      return paramMetadata;
   }   
   
   public boolean isCallable()
   {
      return isCallable;
   }

   /**
    * 
    * Metainformation about single parameter of method.
    */
   public static class ParamMetadata
   {
      private final String paramName;
      
      private final Class<?> paramType;
      
      private final boolean isConvertable;

      public ParamMetadata(String paramName, Class<?> paramType, boolean isConvertable)
      {
         this.paramName = paramName;
         this.paramType = paramType;
         this.isConvertable = isConvertable;
      }
      
      public String getParamName()
      {
         return paramName;
      }

      public Class<?> getParamType()
      {
         return paramType;
      }

      public boolean isConvertable()
      {
         return isConvertable;
      }            
   }

}

